Keep declared and refined function return types separate in FuncType#2716
Merged
ChristianGruen merged 2 commits intoJul 8, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The function return type in the
FuncTypeof a function item may currently be affected by the type of the function body. This may be helpful for enabling optimizations based on a narrower type, but it makesinstance oftests go wrong, as in the following, returningtrue, where the correct result isfalse:The changes here attempt to achieve both, optimization and correctness of
instance of, by keeping the refined type in addition to the declared type inFuncType. TheeqandinstanceOfmethods still stick to the declared type, while consumers with optimization in mind now refer to the refined type.As
instance ofnow observes the declared type rather than the inferred body type, the same holds for the type reported byinspect:function/inspect:typeand by adaptive/BaseX serialization: an inline function without a declared return type is now shown asfn() as item()*instead of by its body type. This keeps the displayed type consistent with whatinstance ofchecks.This also uncovered a different bug: both
ClosureandVarare normalizing types tonullwhen they areeq(ITEM_ZM). This held for unresolved type references, because such a reference - a forward reference, e.g. to a recursive record type likefn:schema-type-record- dereferences toitem()until it has been resolved. SinceSeqType.eqdereferences before comparing, the reference compared equal toitem()*and its declared type was dropped. Once dropped it was never restored, so the declared type was effectively never enforced (e.g.let $x as fn:schema-type-record* := 1was silently accepted). As a collateral fix, this is solved by havingSeqType.eqcompare unresolvedTypeRefs by object identity. This also keepsbuilt-in-record-type-305passing, which would otherwise have regressed.Regression tests have been added for all changes. QT4 test cases
built-in-record-type-303andbuilt-in-record-type-304also now pass.